const getAppURL = (app) => {
  const env = getEnv()

  return APP_URL[env][app]
}

const getEnv = () => {
  const {href, protocol} = window.location

  if (href.includes('localhost')) {
    return 'dev'
  }

  if (protocol === 'https:') {
    return 'prod'
  }

  return 'staging'
}

const APP_URL = {
  dev: {
    'student-program': 'http://localhost:3000',
    'subscription': 'http://localhost:3004',
    'practise-diary': 'http://localhost:3001'
  },
  staging: {
    'student-program': 'http://staging.school.thoughtworks.cn/learn/program-center/student/index.html#/',
    'subscription': 'http://staging.school.thoughtworks.cn/learn/subscription/index.html#/',
    'practise-diary': 'http://staging.school.thoughtworks.cn/learn/practise-diary/index.html#/'
  },
  prod: {
    'student-program': 'https://school.thoughtworks.cn/learn/program-center/student/index.html#/',
    'subscription': 'https://school.thoughtworks.cn/learn/subscription/index.html#/',
    'practise-diary': 'https://school.thoughtworks.cn/learn/practise-diary/index.html#/'
  }
}
export default getAppURL
